﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace ConsoleAppNetFramework
{
    internal class Program
    {
        static void Main(string[] args)
        {
            /*Timer timer = new Timer();
            timer.Interval = 1000;
            Boy boy = new Boy();
            timer.Elapsed += boy.Action;
            timer.Start();
            Console.ReadLine();*/

            //string s = null;
            //Console.WriteLine(s?[0]);

            /*    Sentence sentence = new Sentence();
                Console.WriteLine(sentence[3]);
                sentence[3] = "kangaroo";
                Console.WriteLine(sentence[3]);*/

            //Console.WriteLine(Foo.X);
            //int count = 123;
            //Console.WriteLine(nameof(count));

            //House mansion1 = new House { Name = "McMansion", Mortgage = 250000 };
            //House mansion2 = (House)mansion1.Clone();

            /*  Override over = new Override(123);
              BaseClass b1 = over;
              over.Foo();
              b1.Foo(); // 通过父类变量调用Foo方法，是调用父类的Foo方法，但是父类的Foo方法被子类重写了，所以最终还是调用到子类的Foo方法了

              Hider hider = new Hider();
              BaseClass b2 = hider;
              hider.Foo();
              b2.Foo(); // 子类没有覆写父类的同名方法，所以虽然实例是子类的但是变量是父类的，通过父类变量调用Foo方法就是调用父类的Foo方法了

              object y = "5";
              int z = (int)y;*/

            /**/BorderSides2 leftRight = BorderSides2.Left | BorderSides2.Right;
            //if ((leftRight & BorderSides2.Left) != 0)
            //{
            //    Console.WriteLine("Include Left");
            //}
            Console.WriteLine(leftRight & BorderSides2.Left);
            string formatted = leftRight.ToString();
            Console.WriteLine(formatted);

            /*BorderSides2 s = BorderSides2.Left;
            s |= BorderSides2.Right;
            Console.WriteLine(s == leftRight);
            s ^= BorderSides2.Right;
            Console.WriteLine(s);

            for (int i = 0; i < 17; i++)
            {
                BorderSides side = (BorderSides)i;
                Console.WriteLine(IsFlagDefined(side)+" "+side);
            }

            bool IsFlagDefined(Enum e)
            {
                decimal d;
                return !decimal.TryParse(e.ToString(), out d);
            }*/
        }

       
    }

    class Foo
    {
        public static Foo Instance = new Foo();
        public static int X = 3;
        public static int Y = 3;
        Foo() { Console.WriteLine(X); }
    }
    class Sentence
    {
        string[] words = "The quick brown fox".Split();
        public string this[int wordNum]
        {
            get { return words[wordNum]; }
            set { words[wordNum] = value; }
        }
        //public string this[int index] =>words[index];
        public const string Message = "Hello World";

    }
    class Boy
    {
        internal void Action(object sender, ElapsedEventArgs e)
        {
            Console.WriteLine("boy jump");
        }
    }

    partial class PaymentForm
    {
        partial void ValidatePayment(decimal amount);
    }
    partial class PaymentForm
    {
        partial void ValidatePayment(decimal amount)
        {
            if (amount > 0)
            {

            }
        }
    }

    public class Assert
    {
        public string Name;
        public virtual Assert Clone() => new Assert() { Name = Name };
    }

    public class House : Assert
    {
        public decimal Mortgage;
        public override Assert Clone()
        {
            return new House()
            {
                Mortgage = Mortgage,
                Name = Name
            };
        }
    }

    public class BaseClass
    {
        public int X;
        public BaseClass() { X = 2; }
        public BaseClass(int x) { X = x; }
        public virtual void Foo() => Console.WriteLine($"{nameof(BaseClass)}.Foo");
    }


    public class Override : BaseClass
    {
        public Override(int x) : base(x) { }
        public override void Foo() => Console.WriteLine($"{nameof(Override)}.Foo");
    }

    public class Hider : BaseClass
    {
        public Hider() { Console.WriteLine(X); }
        public new void Foo() => Console.WriteLine($"{nameof(Hider)}.Foo");
    }

    [Flags]
    enum BorderSides
    {
        None = 0,
        Left = 1,
        Right = 2,
        Top = 4,
        Bottom = 8,
    }

    [Flags]
    enum BorderSides2
    {
        None = 0,
        Left = 1,
        Right = 1 << 1,
        Top = 1 << 2,
        Bottom = 1 << 3,
    }
}
